package 力扣._00周赛._144双周赛.问题2;

class Solution {
    public long shiftDistance(String s, String t, int[] nextCost, int[] previousCost) {
        // 计算每一个字符，向后向前切换的代价，选择最小的执行
        long cost = 0;
        for (int i = 0; i < s.length(); i++) {
            char sChar = s.charAt(i);
            char tChar = t.charAt(i);
            if (sChar == tChar) {
                continue;
            }
            // 向前切换的代价
            long preCost = 0;
            for (int j = 0; j < ((sChar- tChar) + 26) % 26; j++) {
                preCost+= previousCost[(sChar - 'a' - j + 26) % 26];
            }
            // 向后切换的代价
            long nexCost = 0;
            for (int j = 0; j < ((tChar-sChar ) + 26) % 26; j++) {
                nexCost += nextCost[(sChar - 'a' + j + 26) % 26];
            }
            cost += Math.min(preCost, nexCost);
        }
        return cost;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
//        String s = "ccdbbcaadb";
//        String t = "aadbbdaaac";
//        int[] nextCost = {6,6,9,8,2,4,10,10,6,4,9,5,5,5,2,7,9,7,4,1,4,10,1,5,2,4};
//        int[] previousCost = {0,4,5,6,7,10,5,5,8,1,1,10,7,8,10,8,7,2,3,3,6,3,0,6,4,0};
//
        String s = "abab";
        String t = "baba";
        int[] nextCost = {100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
        int[] previousCost = {1,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};


        long result = solution.shiftDistance(s, t, nextCost, previousCost);
        System.out.println(result);
    }
}